package cz.proks.bank.manager;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cz.proks.bank.dao.OperationLogDao;
import cz.proks.bank.domain.Account;
import cz.proks.bank.domain.Bank;
import cz.proks.bank.domain.OperationLog;
import cz.proks.bank.domain.OperationLog.OperationType;

@Service
public class OperationLogManager {
	@Autowired
	OperationLogDao logDao;
	
	public OperationLog buildLog(Account account, Bank bank, OperationType type, Date date, String additionalInfo) {
		OperationLog operationLog = new OperationLog();
		
		operationLog.setAccount(account);
		operationLog.setBank(bank);
		operationLog.setType(type);
		operationLog.setDate(date);
		operationLog.setAdditionalInfo(additionalInfo);
		
		return operationLog;
	}
	
	public OperationLog createLog(Account account, Bank bank, OperationType type, Date date, String additionalInfo) {
		OperationLog log = buildLog(account, bank, type, date, additionalInfo);		
		
		log =createLog(log);
		
		return log;
	}
	
	public OperationLog createLog(OperationLog log) {
		if (log == null)
			return null;
		
		log = logDao.create(log);
		
		return log;		
	}
	
	public List<OperationLog> listByAccount(Account account) {
		List<OperationLog> logs = logDao.listByAccount(account);
		
		return logs;
	}
}
